<template>
  <div class="common-layout">
    <el-container>
      <el-header>
        <div class="header-content">
          <img style="height: 150px;width: 150px" src="@/logo.png" alt="Logo" class="header-logo">
          <div>
            <img src="@/img.png" alt="Logo-text" style="height: 45px;margin-top: 30px" class="header-logotext">
            <p STYLE="width: 1000px;margin-left: 10px;margin-top: 10px">NEUSOFT&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;SMART&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;COMMUNITY</p>
          </div>
          <div class="avatar">
            <el-avatar :size="55" :icon="UserFilled"/>
          </div>
        </div>
      </el-header>
      <el-container>
        <el-aside class="aside">
          <el-menu router default-active="1">
            <el-menu-item style="height: 100px" index="announcement-management" class="first">
              <el-icon>
                <location/>
              </el-icon>
              <span>公告发布</span>
            </el-menu-item>
            <el-menu-item style="height: 100px" index="complaints-management">
              <el-icon>
                <icon-menu/>
              </el-icon>
              <span>投诉管理</span>
            </el-menu-item>
            <el-menu-item style="height: 100px" index="visitor-management">
              <el-icon>
                <document/>
              </el-icon>
              <span>访客通行</span>
            </el-menu-item>
            <el-menu-item style="height: 100px" index="park-management">
              <el-icon>
                <setting/>
              </el-icon>
              <span>车位管理</span>
            </el-menu-item>
            <el-menu-item style="height: 100px" index="maintenance-management">
              <el-icon>
                <setting/>
              </el-icon>
              <span>报事处理</span>
            </el-menu-item>
            <el-menu-item style="height: 100px" index="payment-management">
              <el-icon>
                <setting/>
              </el-icon>
              <span>缴费记录</span>
            </el-menu-item>

          </el-menu>
        </el-aside>

        <el-main class="main">
          <div class="m-4">
            <h2 style="margin-left: 80px;margin-top: 40px">投诉管理</h2>
            <el-divider></el-divider>
            <el-cascader
                placeholder="请输入"
                :options="options"
                :props="props"
                filterable
            />
            <!--            <el-button style="margin-right: 20px" class="button1" type="button">添加订单</el-button>-->
            <!--            <el-button style="margin-right: 20px" class="button2" type="button">删除订单</el-button>-->
          </div>
          <el-table :data="tableData" style="width: 100%">
            <el-table-column fixed prop="complainUrl" label="投诉图片" width="300px">

              <template #default="scope">
                <el-image :src="scope.row.complainUrl" style="width:100px ;"></el-image>
                <div style="text-align: center;width: 100px;">图片</div>
              </template>
            </el-table-column>
            <el-table-column fixed prop="name" label="用户姓名" width="200"/>
            <el-table-column prop="complainState" label="投诉状态" width="100"/>
            <el-table-column prop="complainId" label="投诉id" width="100" v-if="false"/>
            <el-table-column prop="complainTime" label="投诉时间" width="200"/>
            <el-table-column prop="complainArea" label="投诉地点" width="200"/>
            <el-table-column prop="complainDescribe" label="投诉描述" width="500"/>
            <el-table-column prop="userId" label="用户id" width="0" v-if="false"/>


            <el-table-column fixed="right" label="操作" width="200">
              <template #default="data">
                <el-button link type="primary" size="small" @click="handleClick(data.row)"
                           :disabled="data.row.status === '已处理'">
                  {{ data.row.status === '已处理' ? '已处理' : '处理' }}
                </el-button>
              </template>
            </el-table-column>
          </el-table>
        </el-main>

      </el-container>
    </el-container>
  </div>
</template>

<script setup>
import {Document, Location, Menu as IconMenu, Setting, UserFilled} from '@element-plus/icons-vue'
import {onMounted, ref} from 'vue';
import *as complain from '../api/complain-management'
import *as announcement from '../api/announcement-management'
import *as complainMan from '../api/complain-management'
import * as maintence from "@/api/maintenance";


const props = defineProps({
  multiple: Boolean,

})
const tableData = ref([])
function formatDate(isoDate) {
  const date = new Date(isoDate);
  const year = date.getFullYear();
  const month = date.getMonth() + 1; // getMonth() 返回的是从 0 开始的月份，所以需要加 1
  const day = date.getDate();
  const hours = date.getHours();
  const minutes = date.getMinutes();
  const seconds = date.getSeconds();

  // 构建格式化后的字符串
  const formattedDate = `${year}年${month}月${day}日${hours}:${minutes}:${seconds}`
  return formattedDate;
}

onMounted(() => {
  const updateInterval = setInterval(() => {
    complain.complain_query().then((res) => {
      tableData.value = res.data;
      for (let i = 0; i < tableData.value.length; i++) {
        tableData.value[i].complainTime = formatDate(tableData.value[i].complainTime)
      }
    })
  }, 1000);
  // 在这里可以执行一些初始化操作
});

const handleClick = (row) => {
  if (row.complainState == "已处理") {
    alert("该报事已处理，请勿点击！")
  } else {
    row.status = '已处理';
    row.complainState = "已处理"
    const notice = {
      noticeText: row.name + "的投诉已受理，在两个工作日内处理完毕",
      userId: row.userId,
      noticeType: "投诉反馈"
    }
    announcement.announcement_add(notice).then((res) => {
      const complain = {
        complainId: row.complainId,
        complainState: "已处理"
      }
      complainMan.complain_updataState(complain).then((res) => {
        alert("处理完成")
      })
    })

  }

}


const options = [
  {
    value: 'guide',
    label: 'Guide',
    children: [
      {
        value: 'disciplines',
        label: 'Disciplines',
        children: [
          {
            value: 'consistency',
            label: 'Consistency',
          },
          {
            value: 'feedback',
            label: 'Feedback',
          },
          {
            value: 'efficiency',
            label: 'Efficiency',
          },
          {
            value: 'controllability',
            label: 'Controllability',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'side nav',
            label: 'Side Navigation',
          },
          {
            value: 'top nav',
            label: 'Top Navigation',
          },
        ],
      },
    ],
  },
  {
    value: 'component',
    label: 'Component',
    children: [
      {
        value: 'basic',
        label: 'Basic',
        children: [
          {
            value: 'layout',
            label: 'Layout',
          },
          {
            value: 'color',
            label: 'Color',
          },
          {
            value: 'typography',
            label: 'Typography',
          },
          {
            value: 'icon',
            label: 'Icon',
          },
          {
            value: 'button',
            label: 'Button',
          },
        ],
      },
      {
        value: 'form',
        label: 'Form',
        children: [
          {
            value: 'radio',
            label: 'Radio',
          },
          {
            value: 'checkbox',
            label: 'Checkbox',
          },
          {
            value: 'input',
            label: 'Input',
          },
          {
            value: 'input-number',
            label: 'InputNumber',
          },
          {
            value: 'select',
            label: 'Select',
          },
          {
            value: 'cascader',
            label: 'Cascader',
          },
          {
            value: 'switch',
            label: 'Switch',
          },
          {
            value: 'slider',
            label: 'Slider',
          },
          {
            value: 'time-picker',
            label: 'TimePicker',
          },
          {
            value: 'date-picker',
            label: 'DatePicker',
          },
          {
            value: 'datetime-picker',
            label: 'DateTimePicker',
          },
          {
            value: 'upload',
            label: 'Upload',
          },
          {
            value: 'rate',
            label: 'Rate',
          },
          {
            value: 'form',
            label: 'Form',
          },
        ],
      },
      {
        value: 'data',
        label: 'Data',
        children: [
          {
            value: 'table',
            label: 'Table',
          },
          {
            value: 'tag',
            label: 'Tag',
          },
          {
            value: 'progress',
            label: 'Progress',
          },
          {
            value: 'tree',
            label: 'Tree',
          },
          {
            value: 'pagination',
            label: 'Pagination',
          },
          {
            value: 'badge',
            label: 'Badge',
          },
        ],
      },
      {
        value: 'notice',
        label: 'Notice',
        children: [
          {
            value: 'alert',
            label: 'Alert',
          },
          {
            value: 'loading',
            label: 'Loading',
          },
          {
            value: 'message',
            label: 'Message',
          },
          {
            value: 'message-box',
            label: 'MessageBox',
          },
          {
            value: 'notification',
            label: 'Notification',
          },
        ],
      },
      {
        value: 'navigation',
        label: 'Navigation',
        children: [
          {
            value: 'menu',
            label: 'Menu',
          },
          {
            value: 'tabs',
            label: 'Tabs',
          },
          {
            value: 'breadcrumb',
            label: 'Breadcrumb',
          },
          {
            value: 'dropdown',
            label: 'Dropdown',
          },
          {
            value: 'steps',
            label: 'Steps',
          },
        ],
      },
      {
        value: 'others',
        label: 'Others',
        children: [
          {
            value: 'dialog',
            label: 'Dialog',
          },
          {
            value: 'tooltip',
            label: 'Tooltip',
          },
          {
            value: 'popover',
            label: 'Popover',
          },
          {
            value: 'card',
            label: 'Card',
          },
          {
            value: 'carousel',
            label: 'Carousel',
          },
          {
            value: 'collapse',
            label: 'Collapse',
          },
        ],
      },
    ],
  },
  {
    value: 'resource',
    label: 'Resource',
    children: [
      {
        value: 'axure',
        label: 'Axure Components',
      },
      {
        value: 'sketch',
        label: 'Sketch Templates',
      },
      {
        value: 'docs',
        label: 'Design Documentation',
      },
    ],
  },
]
</script>
<style scoped>
.common-layout {
  position: fixed;
  top: 0;
  left: 0;
  right: 0;
  bottom: 0;
  overflow: hidden; /* 隐藏滚动条 */
}

.avatar {
  margin-left: 400px;
}

.header-logo {
  float: left;
  width: 100px;
  height: auto;
  margin-top: 10px;
  margin-left: -175px;
}

.header-logotext {
  margin-top: 40px;
}

.header-content {
  display: flex;
  align-items: center;
  border-width: 1px;
  border-bottom-style: groove;
  border-bottom-color: #cccccc;
  position: absolute;
  left: 10%; /* 图片和标题距离左侧20% */
  width: 100%; /* 可根据实际情况调整，确保内容不会溢出 */
}

.aside {
  position: absolute;
  top: 160px;
  left: 0;
  bottom: 0;
  width: 200px;
  height: calc(100% - 60px);
  border: 1px solid #ccc;
}

span {
  font-size: 18px;
}

.first {
  margin-top: 0px;
}

.main {
  flex: 1; /* main占据剩余空间 */
  border-radius: 4px;
  position: absolute;
  top: 150px;
  left: 200px;
  right: 0;
  bottom: 0;
}

.el-header {
  flex: 0 0 15%; /* header占据20%高度，且不缩放 */
  line-height: 1; /* 重置line-height，避免继承影响 */
  align-items: center; /* 垂直居中 */
  justify-content: space-between; /* 调整为两端对齐，以便在两侧放置元素 */
  padding: 0px 20px; /* 添加内边距以防止内容贴近边缘 */
}

.category-menu {
  list-style-type: none;
  padding-left: 0;
}

.category-menu li {
  margin-bottom: 10px;
}

.category-menu li.active {
  font-weight: bold;
}

.button1 {
  width: 80px;
  height: 30px;
  color: white;
  background: dodgerblue;
  margin-left: 950px;
}

.button2 {
  width: 80px;
  height: 30px;
  margin-right: 30px; /* 根据需要调整间距 */
  color: white;
  background: red;
}

.yichu {
  color: red;
}
</style>